package com.man.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.man.bean.AdminMan;
import com.man.bean.People;
import com.util.JdbcUtil;

public class AdminDao {
	QueryRunner qr = new QueryRunner(JdbcUtil.getDataSource());
	
	//注册账号
	public int saveAdmin(AdminMan admin) {
		int num = 0;
		String sql="insert into d_adminman(account,password,pow) values(?,?,?) ";
	
		try {
			num=qr.update(sql,admin.getAccount(),admin.getPassword(),admin.getPow());
		}catch(SQLException e) {
			e.printStackTrace();
		}
		return num;
	}
	//登录账号
	public int showAdmin(AdminMan admins) {
		int num = 0;
		String sql =sql="select * from d_adminman where account=? and `password`=? and pow=?";; 
		AdminMan admin;
		try {
			System.out.println(admins.getAccount());
			admin=qr.query(sql, new BeanHandler <AdminMan>(AdminMan.class),admins.getAccount(),admins.getPassword(),admins.getPow());
			if(admin==null) {
				return 0;
			}else {
				return 1;
			}
		}catch(SQLException e) {
			e.printStackTrace();
		}
		return num;
	}
	
	

		public int	changePwd(AdminMan peo) {
				int num = 0;
				String sql="UPDATE d_adminman set `password`=?  where pow=? and account=? "; ; 
				try {
					num=qr.update(sql,peo.getPassword(),peo.getPow(),peo.getAccount());
				}catch(SQLException e) {
					e.printStackTrace();
				}
				return num;
		}
	

}
